﻿using System;
using System.Resources;
using System.Globalization;

namespace IceTea.Resources
{
    /// <summary>
    /// Helper class for retrieving the localized resource string
    /// </summary>
    public class ResourceHelper
    {
        private ResourceHelper() { }

        private static ResourceManager _resourceManager = null;
        private static Object lockobj = new Object();

        /// <summary>
        /// ResourceManager property (static)
        /// make sure only one instance of ResourceManager exist in the whole application
        /// </summary>
        public static ResourceManager ResourceManager 
        {
            get
            {
                lock(lockobj)
                {
                    if (_resourceManager == null)
                    {
                        lock (lockobj)
                        {
                            _resourceManager = new ResourceManager(typeof(Resource));
                        }
                    }
                }
                return _resourceManager;
            }
        }

        /// <summary>
        /// Read localized string in resource
        /// </summary>
        /// <param name="resourceName"></param>
        /// <returns></returns>
        public static string ReadString(string resourceName)
        {
            return ResourceHelper.ResourceManager.GetString(resourceName);
        }

        /// <summary>
        /// Read localized string in resource
        /// </summary>
        /// <param name="resourceName"></param>
        /// <param name="cultrue">to read a resource string acoording to specified culture</param>
        /// <returns></returns>
        public static string ReadString(string resourceName, CultureInfo cultrue)
        {
            return ResourceHelper.ResourceManager.GetString(resourceName, cultrue);
        }
    }
}
